﻿<%@ Page Title="" Language="C#" MasterPageFile="~/NestedMasterPage.master" AutoEventWireup="true" CodeBehind="WebShopCart.aspx.cs" Inherits="Web.WebShopCart" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <p style="padding: 10px 0px 10px 0px;">
        <asp:SiteMapPath ID="SiteMapPath1" runat="server" CssClass="sitmap"
            Style="font-family: 幼圆; font-size: medium" Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" > ">
            <PathSeparatorStyle Font-Bold="True" ForeColor="#990000" />
            <CurrentNodeStyle ForeColor="#333333" />
            <NodeStyle Font-Bold="True" />
            <RootNodeStyle Font-Bold="True" />
        </asp:SiteMapPath>
    </p>
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <p>收货地址：<%=address %>&nbsp;【<a href="WebMyAddress.aspx">更换地址</a>】</p>
    <div class="table-responsive">
        <table class="table">
            <caption>我的购物车</caption>
            <thead>
                <tr>
                    <th></th>
                    <th>产品</th>
                    <th>数量</th>
                    <th>价格</th>
                     <th>操作</th>
                </tr>
            </thead>
            <%if (list.Count > 0) {  %>
               <tbody>
                <%foreach (var item in list) %>
                <%{ %>
                <tr>
                    <td>
                        <input type="checkbox" name="abc" v="<%=item.buy_prices %>" value="<%=item.Id %>"  onclick="ck(this)" /></td>
                    <td><%=item.goods_name %></td>
                    <td><%=item.buy_nums %></td>
                    <td><%=item.buy_prices %></td>
                    <td><button type="button" style="text-align:center" v="<%=item.Id %>"  class="btn-link" name="del" onclick="del(this)">删除</button></td>
                </tr>
                <% } %>
            </tbody>
            <tfoot>
               <tr>

                   <td colspan="5" style="text-align:center">
                      总金额：<span style="margin-right:10px;" id="p">0</span>
                       <button type="button" style="text-align:center"  class="btn-danger" id="cartsub">结账</button>
                       <button type="button" style="text-align:center"  class="btn-danger" id="cartdels" onclick="dels()">清空购物车</button>
                   </td>
               </tr>
            </tfoot>
              <% } else { %>
              <tbody>
                  <tr>
                       <td colspan="5" style="text-align:center">暂时没有数据...</td>
                  </tr>
              </tbody>
           <% } %>
        </table>
    </div> 
    <script src="js/jquery.min.js"></script>
     <script src="js/plugins/layer/layer.min.js"></script>
    <script>
        var pirces = 0;
        function ck(ck) {

            var this_prices = $(ck).attr('v');
            var isck = $(ck).is(':checked');
          
            if (isck) {
                pirces = parseFloat(pirces) + parseFloat(this_prices);
            } else {
                pirces = parseFloat(pirces) - parseFloat(this_prices);
            }
            $("#p").html(pirces);
        }
        $("#cartsub").click(function () {
         
            var ck = "";
           
            $("input[name='abc']:checked").each(function () {
                //alert(this.value);
               
                ck += this.value + ",";
               

            });
            $.ajax({
                type: 'post',
                url: '../Hanlder/OrderHandler.ashx?Method=ChangeOrder',
                data: { cks: ck },
                success: function (data) {
                    var index = layer.open({
                        type: 2,
                        title: '结账',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['20%', '60%'],
                        content: 'WebTestPay.aspx?Id=' + ck,
                        end: function () {

                            parent.layer.close(index);
                            window.location.reload();
                            //$('#tb').bootstrapTable('refresh');

                        }
                    });
                }
            });

         
        
        });
        function dels() {
       
            $.ajax({
                type: 'post',
                url: '../Hanlder/OrderHandler.ashx?Method=Dels',
              
                success: function (data) {
                    alert('清空购物车成功');
                    location.reload();
                }
            });
        }
        function del(ck) {
            var this_Id = $(ck).attr('v');
            $.ajax({
                type: 'post',
                url: '../Hanlder/OrderHandler.ashx?Method=Del',
                data: { Id: this_Id },
                success: function (data) {
                    alert('删除成功');
                    location.reload();
                }
            });
        }
    </script>
</asp:Content>
